﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NielsRask.K242.Core;
using System.Threading;
using NielsRask.K242.Core.AI;
using System.Drawing;

namespace RenderTest1
{
	public class Game
	{
		Sector sector;
		Thread updaterThread;
		public void Initialize(int asteroidCount, int playerCount)
		{
			sector = new Sector( new SizeF( 2500, 2500 ) );
			sector.Populate( asteroidCount );

			//Asteroid asteroid = sector.Asteroids[ 0 ];
			////emperor = new Emperor(sector, asteroid);
			//sector.Players.Add( new Emperor( sector, asteroid ) );
			//sector.Players.Add( new Emperor( sector, sector.Asteroids[ 3 ] ) );	// TODO: burde finde en langt væk ..
			for ( int i = 0; i < playerCount && i < asteroidCount; i++ )
				sector.Players.Add( new Emperor( sector, sector.Asteroids[ i ] ) );

			updaterThread = new Thread( UpdateSector );
		}

		public Sector Sector
		{
			get { return sector; }
		}

		public void Run()
		{
			updaterThread.Start();
		}

		public void Exit()
		{
			updaterThread.Abort();
		}

		public void UpdateSector()
		{
			while ( true )
			{
				lock ( Sector )
				{
					sector.Update();
					Thread.Sleep( 500 );
				}
			}
		}

	}
}
